<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
    
function url($path = ''){
    /*$CI = & get_instance();
    $languagekey = (($CI->session->userdata('lang')=='en')?'en/':'');
    
    return base_url().$languagekey.$path;*/
    return base_url().$path;
}
    
function backend_title() {

    $CI = & get_instance();

    $uri = $CI->uri->segment(1);
//    $uri = $CI->uri->uri_string();
    $title = '';
    switch ($uri) {
        case 'login':$title = __('log_in');
            break;
        case 'password-recovery':$title = __('password_recovery');
            break;
        case 'dashboard':$title = __('dashboard');
            break;
        case 'ticket-admin':$title = __('tickets');
            break;
    }
    return $title;
}

function get_pagination_config() {

    $config = array();

    $config['per_page'] = PER_PAGE;
    $config['num_links'] = NUM_LINKS;
    $config['next_link'] = '»';
    $config['prev_link'] = '«';
    $config['first_link'] = '«««';
    $config['last_link'] = '»»»';

    return $config;
}

function get_years_combo($options = array()) {
    // Default categories name
    if (!isset($options['combo_name'])) {
        $options['combo_name'] = 'year';
    }
    $class = '';
    if (isset($options['class'])) {
        $class = 'class="' . $options['class'] . '"';
    }

    $data_options = array();
    $data_options[-1] = __('select_all');
    for ($i = $options['from_year']; $i <= $options['to_year']; $i++) {
        $data_options[$i] = $i;
    }

    if (!isset($options['year'])) {
        $options['year'] = $options['to_year'];
    }

    return form_dropdown($options['combo_name'], $data_options, $options['year'], $class);
}

function get_months_combo($options = array()) {
    // Default categories name
    if (!isset($options['combo_name'])) {
        $options['combo_name'] = 'month';
    }
    $class = '';
    if (isset($options['class'])) {
        $class = 'class="' . $options['class'] . '"';
    }

    $data_options = array();
    $data_options[-1] = __('select_all');
    for ($i = 1; $i <= 12; $i++) {
        $data_options[$i] = $i;
    }

    return form_dropdown($options['combo_name'], $data_options, $options['month'], $class);
}

function get_days_combo($options = array()) {
    // Default categories name
    if (!isset($options['combo_name'])) {
        $options['combo_name'] = 'day';
    }
    $class = '';
    if (isset($options['class'])) {
        $class = 'class="' . $options['class'] . '"';
    }

    $data_options = array();
    $data_options[-1] = __('select_all');
    for ($i = 1; $i <= 31; $i++) {
        $data_options[$i] = $i;
    }

    return form_dropdown($options['combo_name'], $data_options, $options[$options['combo_name']], $class);
}

function get_icon($param) {

    $CI = & get_instance();

    if ($param == 'delete') {

        return '<img src="'.base_url().'assets/style/img/icons/delete.png" title="' . __('delete') . '"/>';
    } elseif ($param == 'edit') {

        return '<img src="'.base_url().'assets/style/img/icons/edit.png" title="' . __('edit') . '"/>';
    } elseif ($param == 'detail') {

        return '<img src="'.base_url().'assets/style/img/icons/detail.png" title="' . __('detail') . '"/>';
    }
}

function __($key = '') {

    $CI = & get_instance();
    $value = $CI->lang->line($key);
    return ($value != '' && $value != NULL) ? $value : '#' . $key;
}

function getWordOfString($string,$len = 30){
    $arr_splitstring = explode(' ',$string, $len+1);
    unset($arr_splitstring[$len]);
    return implode(' ',$arr_splitstring);
}

function filterHTML($str){
    $need_find = array('"','\'');
    $need_replaced = array('“','`');
    return str_replace($need_find,$need_replaced,$str);
}
